home *** CD-ROM | disk | FTP | other *** search
/ QRZ! Ham Radio 8 / QRZ Ham Radio Callsign Database - Volume 8.iso / pc / files / t_unix / j109lxa4.tar / tip.c < prev    next >
C/C++ Source or Header  |  1994-06-04  |  3KB  |  125 lines

  1. /* "Dumb terminal" session command for serial lines
  2.  * Copyright 1991 Phil Karn, KA9Q
  3.  *
  4.  *      Feb '91 Bill Simpson
  5.  *              rlsd control and improved dialer
  6.  */
  7. /* mods by PA0GRI */
  8. #include "global.h"
  9. #include "mbuf.h"
  10. #include "proc.h"
  11. #include "iface.h"
  12. #ifdef UNIX
  13. #include "unixasy.h"
  14. #else
  15. #include "i8250.h"
  16. #endif
  17. #include "asy.h"
  18. #include "tty.h"
  19. #include "session.h"
  20. #include "socket.h"
  21. #include "commands.h"
  22. #include "devparam.h"
  23.  
  24.  
  25. static void tip_out __ARGS((int dev,void *n1,void *n2));
  26.  
  27.  
  28. /* Execute user telnet command */
  29. int
  30. dotip(argc,argv,p)
  31. int argc;
  32. char *argv[];
  33. void *p;
  34. {
  35.     struct session *sp;
  36.     register struct iface *ifp;
  37.     char *ifn;
  38.     int (*rawsave) __ARGS((struct iface *,struct mbuf *));
  39.     int c;
  40.  
  41.     /*Make sure this comes from console - WG7J*/
  42.     if(Curproc->input != Command->input)
  43.         return 0;
  44.  
  45.     if((ifp = if_lookup(argv[1])) == NULLIF){
  46.     tprintf(Badinterface,argv[1]);
  47.         return 1;
  48.     }
  49.     if( ifp->dev >= ASY_MAX || Asy[ifp->dev].iface != ifp ){
  50.         tprintf("Interface %s not asy port\n",argv[1]);
  51.         return 1;
  52.     }
  53.     if(ifp->raw == bitbucket){
  54.         tprintf("tip or dialer session already active on %s\n",argv[1]);
  55.         return 1;
  56.     }
  57.  
  58.     /* Allocate a session descriptor */
  59.     if((sp = newsession(argv[1],TIP,0)) == NULLSESSION){
  60.     tputs(TooManySessions);
  61.         return 1;
  62.     }
  63.  
  64.     /* Save output handler and temporarily redirect output to null */
  65.     rawsave = ifp->raw;
  66.     ifp->raw = bitbucket;
  67.  
  68.     /* Suspend the packet input driver. Note that the transmit driver
  69.      * is left running since we use it to send buffers to the line.
  70.      */
  71.     suspend(ifp->rxproc);
  72.  
  73.     /* Put tty into raw mode */
  74.     sp->ttystate.echo = 0;
  75.     sp->ttystate.edit = 0;
  76.     sockmode(sp->output,SOCK_BINARY);
  77.  
  78.     /* Now fork into two paths, one rx, one tx */
  79.     ifn = if_name( ifp, " tip out" );
  80.     sp->proc1 = newproc(ifn,256,tip_out,ifp->dev,NULL,NULL,0);
  81.     free( ifn );
  82.  
  83.     ifn = if_name( ifp, " tip in" );
  84.     chname( Curproc, ifn );
  85.     free( ifn );
  86.  
  87.     /* bring the line up (just in case) */
  88.     if ( ifp->ioctl != NULL )
  89.         (*ifp->ioctl)( ifp, PARAM_UP, TRUE, 0L );
  90.  
  91.     while((c = get_asy(ifp->dev)) != -1)
  92.         tputc(c & 0x7f);
  93.     tflush();
  94.  
  95.     killproc(sp->proc1);
  96.     sp->proc1 = NULLPROC;
  97.     ifp->raw = rawsave;
  98.     resume(ifp->rxproc);
  99.     keywait(NULLCHAR,1);
  100.     freesession(sp);
  101.     return 0;
  102. }
  103.  
  104.  
  105. /* Output process, DTE version */
  106. static void
  107. tip_out(dev,n1,n2)
  108. int dev;
  109. void *n1,*n2;
  110. {
  111.     struct mbuf *bp;
  112.     int c;
  113.  
  114.     while((c = recvchar(Curproc->input)) != EOF){
  115.         if(c == '\n')
  116.             c = '\r';               /* NL => CR */
  117.         bp = pushdown(NULLBUF,1);
  118.         bp->data[0] = (c & 0x7f);
  119.         asy_send(dev,bp);
  120.         Asy[dev].iface->lastsent = secclock();
  121.     }
  122. }
  123.  
  124.  
  125.